package com.vueblog.webapi.exception;

import com.vueblog.webapi.enums.ResponseEnum;
import com.vueblog.webapi.utils.I18nUtils;
import lombok.Data;
import lombok.EqualsAndHashCode;

/**
 * <p>
 * 自定义异常
 * </p>
 *
 * @author intest
 * @since 2019-07-22
 */
@Data
@EqualsAndHashCode(callSuper = false)
public class BusinessException extends RuntimeException {

    private final Integer code;
    private final String msg;

    public BusinessException() {
        this(ResponseEnum.ERROR);
    }

    public BusinessException(String msg) {
        this.code = ResponseEnum.ERROR.getCode();
        this.msg = msg;
    }

    public BusinessException(Integer code, String msg) {
        this.code = code;
        this.msg = I18nUtils.getKey(msg);
    }

    public BusinessException(ResponseEnum re) {
        this.code = re.getCode();
        this.msg = I18nUtils.getKey(re.getMessage());
    }
}
